package de.jmda.gen.java.impl;

import static de.jmda.core.util.StringUtil.sb;
import de.jmda.core.util.StringUtil;
import de.jmda.gen.GeneratorException;
import de.jmda.gen.impl.DefaultGenerator;
import de.jmda.gen.java.ParameterNameGenerator;

public class DefaultParameterNameGenerator
		extends DefaultGenerator
		implements ParameterNameGenerator
{
	public final static String DEFAULT_PARAMETER_NAME = "parameter_name";

	public DefaultParameterNameGenerator()
  {
	  super();
  }

	public DefaultParameterNameGenerator(String input)
  {
	  super(input);
  }

	@Override
  public StringBuffer generate() throws GeneratorException
  {
		StringBuffer result = super.generate();
		
		if (StringUtil.isBlank(result))
		{
			result = sb(DEFAULT_PARAMETER_NAME);
		}

	  return validate(result);
  }

	protected StringBuffer validate(StringBuffer stringBuffer)
			throws GeneratorException
	{
		if (false == StringUtil.startsWithLower(stringBuffer))
		{
			throw new GeneratorException(
					stringBuffer + " has to start with lower case");
		}

		return stringBuffer;
	}
}